package com.onpositive.realmview.queryeditor;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;

import com.onpositive.realmview.IRealmView;
import com.onpositive.semantic.common.ui.roles.ImageManager;

public final class QueryInput implements IEditorInput,IObjectInput, IPersistableElement {
	private final IRealmView view;

	public QueryInput(IRealmView page) {
		this.view = page;
	}

	public boolean exists() {
		return true;
	}

	public ImageDescriptor getImageDescriptor() {
		return ImageManager.getInstance().getImageDescriptor(view,"", "");
	}
	
	public IRealmView getView(){
		return view;
	}

	public String getName() {
		return view.toString()+"("+view.getParent().toString()+")";
	}

	public IPersistableElement getPersistable() {
		return this;
	}

	public String getToolTipText() {
		return view.toString();
	}

	@SuppressWarnings("rawtypes")
	public Object getAdapter(Class adapter) {
		return null;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((view == null) ? 0 : view.hashCode());
		return result;
	}

	
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		QueryInput other = (QueryInput) obj;
		
		if (view == null) {
			if (other.view != null) {
				return false;
			}
		} else if (!view.equals(other.view)) {
			return false;
		}
		return true;
	}

	public Object getObject() {
		return view;
	}

	public void saveState(IMemento memento)
	{
		AbstractURLInputFactory.saveState(memento, view);		
	}

	public String getFactoryId()
	{
		return AbstractURLInputFactory.getFactoryId();
	}

}